package com.web.servlet;

import com.web.entity.Teacher;
import com.web.service.TeacherService;
import com.web.serviceimpl.TeacherServiceImpl;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/mss")
public class ModifyTeacherServlet extends HttpServlet{
    
    TeacherService teacherService = new TeacherServiceImpl();
    
    //POST提交的请求需要重写doPost()方法来处理
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //1.获取请求参数
        //获取老师修改后的信息，封装成一个老师对象
        req.setCharacterEncoding("utf-8");
        String Tid = req.getParameter("Tid");
        String Tname = req.getParameter("Tname");
        String Tstatus = req.getParameter("Tstatus");
        String CourseID = req.getParameter("CourseID");
        String ClassID = req.getParameter("ClassID");

        //获取老师的信息，封装成一个teacher对象
        Teacher teacher = new Teacher(Tid,Tname,Tstatus,CourseID,ClassID);

        //2. 调用业务逻辑，完成请求处理
        //修改老师信息，不能修改id
        int rows = teacherService.modifyTeacherInfo(teacher);
        
        //3. 生成响应内容，这里返回受影响的行数用于判断是否修改成功
        resp.getWriter().print(rows);

    }
}
